﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace HGZP.PLL
{
  /// <summary>
    /// 模块功能: 统一设置窗口上各个控件的可用性
    /// 模块日期: 2009-2-10
  /// </summary>
    public  class FormControlState
    {
        public static void SetControlState(Control controlGroup, MyEnum.MyBool flag)
        {
            foreach (Control control in controlGroup.Controls)
            {
                if (control is TextBox)
                {
                    if (flag == MyEnum.MyBool.True)
                    {
                        ((TextBox)control).ReadOnly = false;
                    }
                    else
                    {
                        ((TextBox)control).ReadOnly = true;
                    }
                }
                else if (control is CheckBox)
                {
                    if (flag == MyEnum.MyBool.True)
                    {
                        ((CheckBox)control).Enabled = true;
                        
                    }
                    else
                    {
                        ((CheckBox)control).Enabled = false;
                    }
                }
                else if (control is Button)
                {
                    if (flag == MyEnum.MyBool.True)
                    {
                        ((Button)control).Enabled = true;
                    }
                    else
                    {
                        ((Button)control).Enabled = false;
                    }
                }
                else if (control is ComboBox)
                {
                    if (flag == MyEnum.MyBool.True)
                    {
                        ((ComboBox)control).Enabled = true;
                    }
                    else
                    {
                        ((ComboBox)control).Enabled = false;
                    }
                }
                else if (control is DateTimePicker)
                {
                    if (flag == MyEnum.MyBool.True)
                    {
                        ((DateTimePicker)control).Enabled = true;
                    }
                    else
                    {
                        ((DateTimePicker)control).Enabled = false;
                    }
                }
                //dateTimePicker
            }
        }

        public static void SetControlCheckedState(Control controlGroup, MyEnum.MyBool flag)
        {
            foreach (Control control in controlGroup.Controls)
            {
                if (control is CheckBox)
                {
                    if (flag == MyEnum.MyBool.True)
                    {
                        ((CheckBox)control).Checked = true;

                    }
                    else
                    {
                        ((CheckBox)control).Checked = false;
                    }
                }
            }
        }
    }
}
